import gtk
import os
import information
import pickle
import friends
import net
import account

class mainGUI:
    def __init__(self,modulePath,pluginBaseUri):
        self._modulePath = modulePath
        self._pluginBaseUri = pluginBaseUri
        #init UI
        self.builder = gtk.Builder()
        self.builder.add_from_file(os.path.join(self._modulePath,"ui/main.glade"))
        self.builder.connect_signals(self)
        #init test variables
        self.user1 = "e3ed0aa0e3c28c0c998440f4b4060ec2dae9b4d1"
        self.user2 = "3d8445d60ceef2ce9e838f32fad93d33ed954632"
        self.fr = friends.friendsGroup([friends.getGlobalAccount(self.user1),friends.getGlobalAccount(self.user2)])
        #initiate field values
        self._info1 = self.builder.get_object("info1Entry")
        self._info2 = self.builder.get_object("info2Entry")
        info = information.getInformation('test/info',friends.getGlobalAccount(self.user1),self.fillInfo1,self.fr)
        if info:
            self._info1.set_text(info.getData())
        info = information.getInformation('test/info',friends.getGlobalAccount(self.user2),self.fillInfo2,self.fr)
        if info:
            self._info2.set_text(info.getData())
        
    def getMainObject(self):
        return self.builder.get_object("mainVbox")
    
    def fillInfo1(self,infoObj):
        if infoObj:
            self._info1.set_text(infoObj.getData())

        
    def fillInfo2(self,infoObj):
        if infoObj:
            self._info2.set_text(infoObj.getData())

            
    def on_info1Entry_changed(self,widget,data=None):
        if self.user1 == account.getMyAccount().getID():
            information.setPersonalInformation('test/info',self.fr,self._info1.get_text())
        
    def on_info2Entry_changed(self,widget,data=None):
        if self.user2 == account.getMyAccount().getID():
            information.setPersonalInformation('test/info',self.fr,self._info2.get_text())
    